﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test_knowledge
{
    public partial class Form1 : Form
    {
        Model.Context db = new Model.Context();

        public Form1()
        {
            InitializeComponent();
        }

        private void searchBtn_Click(object sender, EventArgs e)
        {

            FindClient(searchTB.Text);

        }

        public void FindClient(string text)
        {
            try
            {
                int ID = Int32.Parse(text);
                var client = from t in db.Clients
                             where t.ClientId == ID
                             select t;
                var clientCollection = client.ToList();
                nameTB.Text = clientCollection[0].Name;
                surnameTB.Text = clientCollection[0].Surname;
                FindBuskets(ID);


            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

        public void FindBuskets(int ID)
        {
            var buskets = from t in db.Buskets
                          where t.ClientId == ID
                          select t;

            var busketCollection = buskets.ToList();

            BindingSource binding = new BindingSource();
            binding.DataSource = busketCollection;
            dgw.DataSource = binding;
        }
    }
}
